<%@page import="com.interfaces.SendAgentController"%>
<%@ page import="com.interfaces.VisaApplicationInfoController" %>
<%@ page import="java.util.Random" %>
<%@ page import="com.core.sysDict.*" %>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page import="com.core.sysDict.SysDictJsp" %>
<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>签证信息</title>
    <!-- Tell the browser to be responsive to screen width -->
    <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">

    <%
        String path = request.getContextPath();
        path = "/".equals(path)?"":path;
        request.setAttribute("path", path);
        String sysDictJson=SysDictJsp.getSysDictJson(session);
    %>
    <script type="text/javascript">
        var path = "${path}";
    </script>

    <!-- Bootstrap 3.3.6 -->
    <link rel="stylesheet" href="${path}/public/adminlte/bootstrap/css/bootstrap.min.css">
    <!-- Font Awesome -->
    <link rel="stylesheet" href="${path}/public/font-awesome-4.7.0/css/font-awesome.min.css">
    <!-- Ionicons -->
    <link rel="stylesheet" href="${path}/public/ionicons/ionicons.min.css">
    <!-- Select2 -->
  	<link rel="stylesheet" href="${path}/public/adminlte/plugins/select2/select2.min.css">
    <!-- DataTables -->
    <link rel="stylesheet" href="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.css">
    <!-- Theme style -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/AdminLTE.min.css">
    <!-- AdminLTE Skins. We have chosen the skin-blue for this starter
          page. However, you can choose any other skin. Make sure you
          apply the skin class to the body tag so the changes take effect.
    -->
    <link rel="stylesheet" href="${path}/public/adminlte/dist/css/skins/_all-skins.min.css">

    <link rel="stylesheet" href="${path}/css/common.css">

    <!-- HTML5 Shim and Respond.js IE8 support of HTML5 elements and media queries -->
    <!-- WARNING: Respond.js doesn't work if you view the page via file:// -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
</head>
<!--
BODY TAG OPTIONS:
=================
Apply one or more of the following classes to get the
desired effect
|---------------------------------------------------------|
| SKINS         | skin-blue                               |
|               | skin-black                              |
|               | skin-purple                             |
|               | skin-yellow                             |
|               | skin-red                                |
|               | skin-green                              |
|---------------------------------------------------------|
|LAYOUT OPTIONS | fixed                                   |
|               | layout-boxed                            |
|               | layout-top-nav                          |
|               | sidebar-collapse                        |
|               | sidebar-mini                            |
|---------------------------------------------------------|
-->
<body >
<div class="container">
            <div class="box box-primary">
                <!-- /.box-header -->
                <div class="box-body">
                    <div class="row">
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="sendAgencyId">送签社</label>
                                <select  class="form-control" id="sendAgencyId">
                                </select>
                            </div>
                        </div>
                        <div class="col-md-4">
                            <div class="form-group">
                                <label for="txtvisitorName">1号人姓名</label>
                                <div class="row">
                                	<div class="col-md-10">
                                	<input type="text" class="form-control" id="txtvisitorName">
                                	</div>
	                                <div class="col-md-2">
	                                <button type="submit" id="btnSearch" class="btn btn-primary" >搜 索</button>
	                                </div>
                                </div>
                            </div>
                        </div>
                    </div>
                    <div class="row">
                        <div class="col-md-12 text-right">
                            
                            <button class="btn btn-primary" onclick="btnExcel()">导出归国报告书</button>
                            <button type="submit" id="btnAdd" class="btn btn-primary ">新增签证信息</button>
                        </div>
                    </div>
                </div>
            </div>
            <!-- /.box -->
            <div class="box box-primary">
                <!-- /.box-header -->
                <div class="box-body">
                    <table id="dg" class="table table-bordered table-hover">
                        
                    </table>
                </div>
                <!-- /.box-body -->
            </div>
</div>
<!-- ./wrapper -->

<div class="modal fade" id="modelContainer" role="basic" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
        </div>
    </div>
</div>

<!-- REQUIRED JS SCRIPTS -->

<!-- jQuery 2.2.3 -->
<script src="${path}/public/adminlte/plugins/jQuery/jquery-2.2.3.min.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="${path}/public/adminlte/bootstrap/js/bootstrap.min.js"></script>
<!-- DataTables -->
<script src="${path}/public/adminlte/plugins/datatables/jquery.dataTables.min.js"></script>
<script src="${path}/public/adminlte/plugins/datatables/dataTables.bootstrap.min.js"></script>
<!-- Select2 -->
<script src="${path}/public/adminlte/plugins/select2/select2.full.min.js"></script>
<!-- SlimScroll -->
<script src="${path}/public/adminlte/plugins/slimScroll/jquery.slimscroll.min.js"></script>
<!-- FastClick -->
<script src="${path}/public/adminlte/plugins/fastclick/fastclick.js"></script>
<!-- AdminLTE App -->
<script src="${path}/public/adminlte/dist/js/app.min.js"></script>
<!-- 字典-->
<script src="${path}/js/sysDict.js"></script>
<!-- Optionally, you can add Slimscroll and FastClick plugins.
     Both of these plugins are recommended to enhance the
     user experience. Slimscroll is required when using the
     fixed layout. -->
<!-- page script -->
<script>
	var table;
	var url = window.location.search;
	var arr=url.split('&');
	var curid = "tab_"+arr[arr.length-2];
	var sysDict='<%=sysDictJson %>';
	var re = JSON.parse(sysDict); 
	window.onload=function(){
    
    init();
    $("#checkAll").click(function () {
      var check = $(this).prop("checked");
      $(".checkchild").prop("checked", check);
		});
	
    };	
    function formatRepo (repo) {
      if (repo.loading) {return repo.text;}
      return repo.text+"("+repo.id+")";
    }
    function formatRepoSelection (repo) {
    return repo.text ; 
    }
    $("#sendAgencyId").select2({
	language: "zh-CN",
	width: "100%",
  	ajax: {
        url: "${path}<%=SendAgentController.URL_SEARCH%>",
        dataType: 'json',
        delay: 1000,
        type:"post",
        data: function (params) {
        params.page = params.page || 1;
          return {
            code: params.term, // 关键字
            curPage: params.page, 
            pageSize: 10,
	        singlePage: 0          
          };
        },
        processResults: function (data, params) {
          params.page = params.page || 1;
          return {
            results: data.items,//items:数据 data.total_count:总记录数,items中，字段id为option中的value值，
            pagination: {
              more: (params.page * 10) < data.total_count //页数*每页记录数小于总记录数时，可记录下拉
            }
          };
        },
        cache: true
      },
      escapeMarkup: function (markup) { return markup; },
      minimumInputLength: 0,
      templateResult: formatRepo,
      templateSelection: formatRepoSelection
	});
	function init() {
    	
        table=$('#dg').DataTable({
        	language: {
			        "sProcessing": "处理中...",
			        "sLengthMenu": "显示 _MENU_ 项结果",
			        "sZeroRecords": "没有匹配结果",
			        "sInfo": "显示第 _START_ 至 _END_ 项结果，共 _TOTAL_ 项",
			        "sInfoEmpty": "显示第 0 至 0 项结果，共 0 项",
			        "sInfoFiltered": " ",
			        "sInfoPostFix": "",
			        "sSearch": "搜索:",
			        "sUrl": "",
			        "sEmptyTable": "表中数据为空",
			        "sLoadingRecords": "载入中...",
			        "sInfoThousands": ",",
			        "oPaginate": {
			            "sFirst": "首页",
			            "sPrevious": "上页",
			            "sNext": "下页",
			            "sLast": "末页"
			        },
			        "oAria": {
			            "sSortAscending": ": 以升序排列此列",
			            "sSortDescending": ": 以降序排列此列"
			        }
		   		},
            "iDisplayLength" : 10,
            "paging": true,
            "lengthChange": true,
            "bSort" : false,
            "processing" : true,
            "serverSide" : true,
            "searching": false,
            "ordering": false,
            "autoWidth": false,
            "ajax":{
            	 "url":"${path}<%=VisaApplicationInfoController.URL_DB_SEARCH%>?&"+arr[arr.length-1],
            	 "type":"post",
            },
            "columns":[
            		{
            		"data":"id",
            		"title":"<input type='checkbox' class='check' id='checkAll'>",
            		"defaultContent":"",
            		"render":function(data, type, full, meta){
            			return '<input type="checkbox" name="subcheck" class="checkchild"  value="' + data + '" />';
            			},
            			"bSortable": false
            		},
            		{ "data": "visitorName",
            		  "title":"1号人姓名",
            		  "defaultContent":"无",	
            		  "render":function(data, type, row, meta){
            		  	console.info(data);
            		  	if(typeof(data)=="undefined"){data="暂无"}
            		  	return'<A href="javascript:updateFund(&quot;'+meta.row+'&quot;);">'+ data +'</A>';
            			},
            		 },
            		 { "data": "id",
            		  "title":"签证代码",
            		  "visible": false,
            		  "defaultContent":"无",	
            		  "render":function(data, type, full, meta){
            		  	
            		  	return'<A href="javascript:updateFund(&quot;'+data+'&quot;);">'+ data +'</A>';
            			},
            		 },
            		{ "data": "destVisaId","title":"受付番号","defaultContent":"" },
             		{ "data": "visaType","title":"签证类型","defaultContent":"", "render": function(data, type, full) { return getKey_caption('1002',data,re);}},
             		{ "data": "sendAgentName","title":"送签社","defaultContent":""},
             		{ "data": "incomingDate","title":"入境日期","defaultContent":"" },
             		{ "data": "leaveDate","title":"出境日期","defaultContent":"" },
             		{ "data": "entryPoint" ,"title":"入境口岸","defaultContent":"" },
             		{ "data": "exitPoint" ,"title":"出境口岸","defaultContent":"" },
             		{ "data": "entryFlight" ,"title":"入境航班","defaultContent":"" },
             		{ "data": "exitFlight" ,"title":"出境航班","defaultContent":"" },
             		//{ "data": "submitDate","title":"提交日期","defaultContent":"" },
             		{ 
             		  "data": "state",
             		  "title":"当前状态",
             		  "defaultContent":"",
             		  "render": function(data, type, full) { 
                      return getKey_caption('1001',data,re);
                      }
                   },
            ]
        });
    }
        $("#btnAdd").click(function () {
          	  var VisaInfoID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
              parent.addTab({title: "新增签证信息", url:"${path}<%=VisaApplicationInfoController.URL_GOTO_ADD_UPDATE_PAGE%>?&"+VisaInfoID+"&"+curid, id: VisaInfoID, close: true, single:true,act:1});
        });
        $("#btnSearch").click(function(){
        	var param = {
		        "sendAgentId": $('#sendAgencyId').val(),
		        "visitorName": $('#txtvisitorName').val()
	    	};	
	    	console.info(param)
	    	table.settings()[0].ajax.data = param;
       		table.ajax.reload();

        });
    function btnExcel(){
    	//判断至少写了一项  
    	var checkedNum = $("input[name='subcheck']:checked").length;  
    	if(checkedNum==0){  
        	alert("请至少选择一项!");  
            return false;  
        }  
       	if(confirm("确定导出所选项目?")){  
        	var checkedList = new Array();  
            $("input[name='subcheck']:checked").each(function(){  
            	checkedList.push($(this).val());  
           	});  
            $.ajax({  
            	type:"POST",  
               	url:"${path}<%=VisaApplicationInfoController.URL_BACK_COUNTRY%>",  
                data:{"delitems":checkedList.toString()},    
                success:function(result){  
                	  var re = JSON.parse(result);
                   	  if(re.returnCode=="0"){
                   	 	$("[name='checkbox2']:checkbox").attr("checked",false);  
                       	location.reload();
                   	  }else{
                   	   	alert(re.msg);
                   	  	}
                   },  
           		error:function(request) {      // 设置表单提交出错
                	alert(request);  //登录错误提示信息
            	}
          	});  
       	}  
    }
 	 function updateFund(index){
 	 	var rowTarget=table.row(index).data();
 	 	console.info(rowTarget);
 	 	var visaId =rowTarget.id;
   		var VisaInfoID=new Date().getTime()+''+Math.floor(Math.random() * 8998 + 1000);
    	parent.addTab({title: "修改签证信息", url:"${path}<%=VisaApplicationInfoController.URL_GOTO_UPDATE_PAGE%>?id="+visaId+"&"+VisaInfoID+"&"+curid, id: VisaInfoID, close: true, single:true});
    }   
     function freshOK(){
        console.info("success");
        table.draw( false );
        };  
</script>
</body>
</html>